services:
  sampleapp:
    restart: always
    image: sampleapp:latest
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 8000:8000
    env_file:
      - .env
    command: ["gunicorn", "--bind", "0.0.0.0:8000", "sampleproject.wsgi"]
    depends_on:
    - db
    
  migrate:
    image: sampleapp:latest
    profiles:
      - migrate
    env_file:
      - .env
    command: ["python", "manage.py", "migrate"] 
    depends_on:
    - db

  db:
    image: postgres:15.2
    restart: always
    env_file:
      - .env
    volumes:
      - database:/var/lib/postgresql/data

volumes:
  database: